package com.validator.demo;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.stream.Collectors;

@RestController
public class TestDemoController {


    @RequestMapping(method = {RequestMethod.GET,RequestMethod.POST},value = "/demo1")
    public String testDemo1(@Valid Demo demo, BindingResult bindingResult){
        String detail = bindingResult.getFieldErrors().stream().map(it -> it.getField() + ":" + it.getDefaultMessage()).collect(Collectors.joining(","));
        return detail;
    }


    @RequestMapping(method = {RequestMethod.GET,RequestMethod.POST},value = "/demo2")
    public String testDemo2(@Valid  Demo demo){
        return "SUCCESS";
    }


}
